using Microsoft.Practices.Unity;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;
using Rhino.Mocks;
using UniAspect.UnityCommon;

namespace UniAspect.UnitTests
{
    [TestFixture]
    public class ResolvingDependencies
    {

        public class SomeStubClass
        {

        }

        public class BaseStub<T> : IBaseInterface<T>
        {
            public T DoSomething(T value)
            {
                return value;
            }
        }

        public interface IBaseInterface<T>
        {
            T DoSomething(T value);
        }

        [Test]
        public void OverrideGeneric()
        {
            var container = new UnityContainer();
            container.RegisterSingleton(typeof(IBaseInterface<>), typeof(BaseStub<>));
            var mock = MockRepository.GenerateMock<IBaseInterface<SomeStubClass>>();
            container.RegisterInstance(mock);
            var resolve = container.Resolve<IBaseInterface<SomeStubClass>>();
            Assert.That(resolve, Is.SameAs(mock));
        }
    }
}